<template>
  <!-- 搜索历史记录模块 -->
  <div class="SearchHistory">
    <van-cell title="搜索历史">
      <div v-if="isDeteleShow">
        <span @click="$emit('clear-SearchHistory')">全部删除</span>
        &nbsp;
        <span @click="isDeteleShow = false">完成</span>
      </div>
      <van-icon name="delete-o" v-else @click="isDeteleShow = true" />
    </van-cell>
    <van-cell :title="item" v-for="(item, index) in SearchHistories" :key="index" @click="onSearchItemIndex(item, index)">
      <van-icon name="close" v-show="isDeteleShow" />
    </van-cell>
  </div>
</template>

<script>
export default {
  name: 'SearchHistory',
  data() {
    return {
      isDeteleShow: false
    }
  },
  props: {
    SearchHistories: {
      type: Array,
      require: true
    }
  },
  methods: {
    onSearchItemIndex(item, index) {
      if (this.isDeteleShow) {
        // 删除状态，删除历史记录数据
        this.SearchHistories.splice(index, 1)
      } else {
        // 非删除状态，直接进入搜索
        this.$emit('search', item)
      }
    }
  }
}
</script>

<style></style>
